class Stack {
  constructor() {
    this.arr = [];
  }

  isEmpty() {
    return this.arr.length === 0;
  }

  getSize() {
    return this.arr.length;
  }

  push(data) {
    this.arr.push(data);
  }

  pop() {
    return this.arr.pop();
  }

  top() {
    return this.arr[this.arr.length - 1];
  }
}
var MinStack = function () {
  this.stack = new Stack();
  this.minStack = new Stack();
};

/**
 * @param {number} x
 * @return {void}
 */
MinStack.prototype.push = function (x) {
  if (this.minStack.isEmpty() || x <= this.minStack.top()) {
    this.minStack.push(x);
  }
  this.stack.push(x);
};

/**
 * @return {void}
 */
MinStack.prototype.pop = function () {
  var value = this.stack.pop();
  if (value === this.minStack.top()) {
    this.minStack.pop();
  }
  return value;
};

/**
 * @return {number}
 */
MinStack.prototype.min = function () {
  return this.minStack.top();
};

MinStack.prototype.top = function () {
  return this.stack.top();
};

var minStack = new MinStack();
minStack.push(-2);
minStack.push(0);
minStack.push(-3);
console.log(minStack.min()); //--> 返回 -3.
minStack.pop();
console.log(minStack.top()); // --> 返回 0.
console.log(minStack.min()); // --> 返回 -2.
